const Template = require("../core/template");
class Controller{
	constructor(req, res, config){
		this.req = req;
		this.res = res;
		this.template = new Template(res, config);
	}
	render(filename){
		this.template.render(filename);
	}
	ok(){
		this.res.statusCode = 200;
		this.res.setHeader("Content-Type", "application/json");
		this.res.write(JSON.stringify(this.template.data));
		this.res.end();
	}
	assign(key, value){
		if (key instanceof Object) {
			for (let k in key) {
				this.template.data[k] = key[k];
			}
		} else {
			this.template.data[key] = value;
		}
	}
}
module.exports = Controller;